﻿using Blog.IRepository;
using EiiF_Blog;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Blog.Repository
{
    public class NewsRepository:BaseRepository<BlogNews>,INewsRepository
    {
        public async override Task<List<BlogNews>> Query()
        {
            return await base.Context.Queryable<BlogNews>()
                .Mapper(c => c.type,c=>c.TypeId,c => c.type.Id)
                .Mapper(c=>c.author, c => c.AuthorId, c => c.author.Id)
                .ToListAsync();
        }
        public async override Task<List<BlogNews>> Query(Expression<Func<BlogNews, bool>> func)
        {
            return await base.Context.Queryable<BlogNews>()
                .Where(func)
                .Mapper(c => c.type, c => c.TypeId, c => c.type.Id)
                .Mapper(c => c.author, c => c.AuthorId, c => c.author.Id)
                .ToListAsync();
        }

        public async override Task<List<BlogNews>> Query(int page, int size, RefAsync<int> total)
        {
            return await base.Context.Queryable<BlogNews>()
                .Mapper(c => c.type, c => c.TypeId, c => c.type.Id)
                .Mapper(c => c.author, c => c.AuthorId, c => c.author.Id)
                .ToPageListAsync(page, size, total);
        }

        public async override Task<List<BlogNews>> Query(Expression<Func<BlogNews, bool>> func, int page, int size, RefAsync<int> total)
        {
            return await base.Context.Queryable<BlogNews>()
                .Where(func)
                .Mapper(c => c.type, c => c.TypeId, c => c.type.Id)
                .Mapper(c => c.author, c => c.AuthorId, c => c.author.Id)
                .ToPageListAsync(page, size, total);
        }
    }
}
